package com.example.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClientController {
	
	private static final String EUREKA_SERVER_ID = "microservicecloud-dept";

	/**
	 * 用于服务发现，该对象是服务自身的一种描述
	 */
	@Autowired
	private DiscoveryClient client;
	
	@GetMapping("pro/dev/8081/discovery")
	public Object discovery() {
		List<String> list = client.getServices();
		System.out.println(" *** "+list);
		List<ServiceInstance> instances = client.getInstances(EUREKA_SERVER_ID);
		for(ServiceInstance instance : instances) {
			System.out.println("服务ID："+instance.getServiceId()+"；服务IP："+instance.getHost()+"；服务端口："+instance.getPort()+"；uri："+instance.getUri());
		}
		return this.client;
	}
	
}
